package com.qdsg.modulesihealsdk.utils;


import android.text.TextUtils;

import com.qdsg.modulesihealsdk.entity.IdCardBean;
import com.qdsg.modulesihealsdk.entity.SocialSecurityCardBean;

/**
 * @Description
 * @Author WuJianFeng
 * @Date 2022/11/23 9:46
 */
public class StrUtils {
    /**
     * 解析身份证数据
     */
//                        吴xx            |男|汉族|19960729|xx省xx县xx镇xx村xx               |35xx2419xxxx290xxx|20140214|20240214|xx县公安局         |/9j/4AAQxxxxxxQAAAQABAAD/2wBDAAoHBwgHBgoICxxxxxxxxxxxEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoxxxxx7O|
    protected static IdCardBean idCardBean = new IdCardBean();
    public static IdCardBean parseIdentity(String idStr){
        idCardBean.clearData();
        if (SihealSdkConstant.CARD_NULL.equals(idStr)){
            return idCardBean;
        }
        String [] idStrArr = idStr.split("\\|");
        for (int i = 0; i < idStrArr.length; i++) {
            switch (i){
                case 0:{
                    idCardBean.setName(idStrArr[0].trim());
                    break;
                }
                case 1:{
                    idCardBean.setGender(idStrArr[1].trim());
                    break;
                }
                case 2:{
                    idCardBean.setGroup(idStrArr[2].trim());
                    break;
                }
                case 3:{
                    idCardBean.setBorn(idStrArr[3].trim());
                    break;
                }
                case 4:{
                    idCardBean.setAddress(idStrArr[4].trim());
                    break;
                }
                case 5:{
                    idCardBean.setIdNumber(idStrArr[5].trim());
                    break;
                }
                case 6:{
                    idCardBean.setStartDate(idStrArr[6].trim());
                    break;
                }
                case 7:{
                    idCardBean.setEndDate(idStrArr[7].trim());
                    break;
                }
                case 8:{
                    idCardBean.setIssueAuthority(idStrArr[8].trim());
                    break;
                }
                case 9:{
                    idCardBean.setKeyString(idStrArr[9].trim());
                    break;
                }
                default:
                    break;
            }
        }
        return idCardBean;
    }

    //3506xxx9607290513| 吴xx                        | 男| x族|| 199xxxx9| 330100D1560xxx5007CC3E4673B7473|3|1.00|915600000233010033010015|20151110|20251110|W35xx428|
    protected static SocialSecurityCardBean socialSecurityCardBean = new SocialSecurityCardBean();
    public static SocialSecurityCardBean parseSocialSecurityCard(String socialSecurityCardStr){
        socialSecurityCardBean.clearData();
        if (SihealSdkConstant.CARD_NULL.equals(socialSecurityCardStr)){
            return socialSecurityCardBean;
        }
        socialSecurityCardBean.setSocialCardKxx(socialSecurityCardStr);
        String [] socialSecurityCardArr = socialSecurityCardStr.split("\\|");

        for (int i = 0; i < socialSecurityCardArr.length; i++) {
            switch (i){
                case 0:{
                    socialSecurityCardBean.setSocialSecurityNumber(socialSecurityCardArr[0].trim());
                    break;
                }
                case 1:{
                    socialSecurityCardBean.setName(socialSecurityCardArr[1].trim());
                    break;
                }
                case 2:{
                    socialSecurityCardBean.setGender(socialSecurityCardArr[2].trim());
                    break;
                }
                case 3:{
                    if (!socialSecurityCardArr[3].trim().equals(SihealSdkConstant.GROUP_ERROR)){
                        socialSecurityCardBean.setGroup(socialSecurityCardArr[3].trim());
                    }
                    break;
                }
                case 4:{
                    socialSecurityCardBean.setBornNum(socialSecurityCardArr[4].trim());
                    break;
                }
                case 5:{
                    socialSecurityCardBean.setBorn(socialSecurityCardArr[5].trim());
                    break;
                }
                case 6:{
                    socialSecurityCardBean.setCardIdNum(socialSecurityCardArr[6].trim());
                    break;
                }
                case 7:{
                    socialSecurityCardBean.setCardType(socialSecurityCardArr[7].trim());
                    break;
                }
                case 8:{
                    socialSecurityCardBean.setCardVersion(socialSecurityCardArr[8].trim());
                    break;
                }
                case 9:{
                    socialSecurityCardBean.setInitCode(socialSecurityCardArr[9].trim());
                    break;
                }
                case 10:{
                    socialSecurityCardBean.setCardStartDate(socialSecurityCardArr[10].trim());
                    break;
                }
                case 11:{
                    socialSecurityCardBean.setCardEndDate(socialSecurityCardArr[11].trim());
                    break;
                }
                case 12:{
                    socialSecurityCardBean.setCardNum(socialSecurityCardArr[12].trim());
                    break;
                }
                default:
                    break;
            }
        }
        return socialSecurityCardBean;

    }

    /**
     * 校验检测结果，如果为空则返回字符串0
     * @return
     */
    public static String checkResultEmpty(String result){
        if (!TextUtils.isEmpty(result)){
            return result;
        }
        return "0";
    }
}
